from django.db import models
from order.models import *

class Contract(models.Model):
    STATUS = [
        (1, "使用中"),
        (2, "已到期"),
    ]
    def file_path(uid):
        return 'pdf/{0}'.format(uid)
    
    uid = models.IntegerField()
    rid = models.IntegerField()
    oid = models.IntegerField(null=True)
    period = models.IntegerField()  # months
    create_time = models.DateTimeField(auto_now_add=True)
    status = models.IntegerField(default=1, choices=STATUS)
    pdf_path = models.CharField(max_length=255, null=True)

    def get_info(self):
        dic = dict()
        order = Order.objects.get(id=self.oid)
        dic['ctid'] = self.id
        dic['uid'] = self.uid
        dic['rid'] = self.rid
        dic['oid'] = self.oid
        dic['period'] = self.period
        dic['startTime'] = order.startTime
        dic['price'] = order.price
        dic['status'] = self.status
        dic['pdf_path'] = self.pdf_path
        return dic
